<template>
    <a-card :bordered="false">
        <!-- 查询区域 -->
        <div class="table-page-search-wrapper">
            <div class="table-page-search-wrapper">
                <a-form layout="inline" @keyup.enter.native="searchQuery">
                    <a-row :gutter="24">
                        <a-col :md="6" :sm="8">
                            <a-form-item label="数据来源" :label-col="{ span: 6 }" :wrapper-col="{ span: 16 }">
                                <j-dict-select-tag style="width: 260px" v-model="queryParam.dataSource"
                                                   placeholder="请选择订单类型" dictCode="dataSourceDaily"/>
                            </a-form-item>
                        </a-col>
                        <a-col :md="18" :sm="16">
            <span class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="showOrClose" icon="search" style='margin-left: 10px;'>高级查询</a-button>
            </span>
                        </a-col>
                    </a-row>
                </a-form>
            </div>
            <a-row v-if="show" style="padding-top: 0px">
                <a-col :md="6" :sm="8">
                    <a-form-item label="供应商名称" :label-col="{ span: 6 }" :wrapper-col="{ span: 15 }">
                        <j-dict-select-tag style="width: 260px" v-model="queryParam.supplierCode" placeholder="请选择供应商"
                                           dictCode="supplierName"/>
                    </a-form-item>
                </a-col>
                <a-col :md="6" :sm="8">
                    <a-form-item label="种类编码" :label-col="{ span: 6 }" :wrapper-col="{ span: 16 }">
                        <j-dict-select-tag style="width: 260px" v-model="queryParam.subclassCode" placeholder="请选择种类"
                                           dictCode="subclassCode"/>
                    </a-form-item>
                </a-col>
                <a-col :md="6" :sm="8">
                    <a-form-item label="起始时间(止)" :label-col="{ span: 6 }" :wrapper-col="{ span: 16 }">
                        <a-date-picker valueFormat="YYYY-MM-DD"
                                       v-model="queryParam.synchronizationDateStartBegin"></a-date-picker>
                    </a-form-item>
                </a-col>
                <a-col :md="6" :sm="8">
                    <a-form-item label="起始时间(止)" :label-col="{ span: 6 }" :wrapper-col="{ span: 16 }">
                        <a-date-picker valueFormat="YYYY-MM-DD"
                                       v-model="queryParam.synchronizationDateStartFinish"></a-date-picker>
                    </a-form-item>
                </a-col>
            </a-row>
        </div>
        <!-- 查询区域-END -->

        <!-- table区域-begin -->
        <div>
            <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
                <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{
                selectedRowKeys.length }}</a>项
                <a style="margin-left: 24px" @click="onClearSelected">清空</a>
            </div>

            <a-table
                    ref="table"
                    size="middle"
                    bordered
                    rowKey="id"
                    :columns="columns"
                    :dataSource="dataSource"
                    :pagination="ipagination"
                    :loading="loading"
                    :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
                    @change="handleTableChange">

        <span slot="action" slot-scope="text, record">
          <a @click="toDataSynchronization(record)">关联日志详情</a>
        </span>

            </a-table>
        </div>

        <eipDataSynchronizationInfo-modal ref="modalForm" @ok="modalFormOk"></eipDataSynchronizationInfo-modal>
    </a-card>
</template>

<script>

    import {JeecgListMixin} from '@/mixins/JeecgListMixin'
    import EipDataSynchronizationInfoModal from './modules/EipDataSynchronizationInfoModal'
    import {getAction} from '@/api/manage'

    export default {
        name: 'EipDataSynchronizationInfoList',
        mixins: [JeecgListMixin],
        components: {
            EipDataSynchronizationInfoModal
        },
        data() {
            return {
                flag: true,
                description: 'eip_data_synchronization_info管理页面',
                show: false,                      //高级查询
                visible: false,                   //详情是否打开
                synchronizationDateStartBegin: null,
                synchronizationDateStartFinish: null,
                dataSourceDailyDict: {},           //日志数据来源字典
                subclassCodeDict: {},              //种类编码字典
                purchaserHqCodeDict: {},
                // 表头
                columns: [
                    {
                        title: '采购方编码',
                        align: 'center',
                        dataIndex: 'purchaserCode'
                    },
                    {
                        title: '数据来源',
                        align: 'center',
                        dataIndex: 'dataSource'
                    },
                    {
                        title: '供应商名称',
                        align: 'center',
                        dataIndex: 'supplierName'
                    },
                    {
                        title: '种类编码',
                        align: 'center',
                        dataIndex: 'subclassCode'
                    },
                    {
                        title: '起始时间',
                        align: 'center',
                        dataIndex: 'synchronizationDateStart',
                        customRender: function (text) {
                            return !text ? '' : (text.length > 10 ? text.substr(0, 10) : text)
                        }
                    },
                    {
                        title: '结束时间',
                        align: 'center',
                        dataIndex: 'synchronizationDateEnd',
                        customRender: function (text) {
                            return !text ? '' : (text.length > 10 ? text.substr(0, 10) : text)
                        }
                    },
                    {
                        title: '成功数量',
                        align: 'center',
                        dataIndex: 'successNum'
                    },
                    {
                        title: '失败数量',
                        align: 'center',
                        dataIndex: 'failuresNum'
                    },
                    {
                        title: '操作',
                        dataIndex: 'action',
                        align: 'center',
                        scopedSlots: {customRender: 'action'}
                    }
                ],
                url: {
                    list: '/eipDataSynchronizationInfo/selectForList',
                    // delete: "/eipDataSynchronizationInfo/delete",
                    // deleteBatch: "/eipDataSynchronizationInfo/deleteBatch",
                    // exportXlsUrl: "/eipDataSynchronizationInfo/exportXls",
                    // importExcelUrl: "eipDataSynchronizationInfo/importExcel",
                    dictSourceUrl: '/sys/dict/getDicByCode'
                },
                dictOptions: {}
            }
        },

        computed: {
            importExcelUrl: function () {
                return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
            }
        },
        methods: {
            loadDataSourceDailyDict() {
                let dictParams = {'dictCode': 'dataSourceDaily'}
                getAction(this.url.dictSourceUrl, dictParams).then((res) => {
                    this.dataSourceDailyDict = res
                })
            },
            loadSubClassCodeDict() {
                let dictParams = {'dictCode': 'subclassCode'}
                getAction(this.url.dictSourceUrl, dictParams).then((res) => {
                    this.subclassCodeDict = res
                })
            },
            loadPurchaserHqCodeDict() {
                let dictParams = {'dictCode': 'purchaserHqCode'}
                getAction(this.url.dictSourceUrl, dictParams).then((res) => {
                    this.purchaserHqCodeDict = res
                })
            },
            showOrClose() {//高级查询是否展开
                this.show = !this.show
            },
            toDataSynchronization(record) {
                localStorage.setItem('linkPUID', record.puid)
                this.$router.push({path: '/rzxq'})
            },
            loadData(arg) {
                if (this.flag) {
                    this.loadDataSourceDailyDict()
                    this.loadSubClassCodeDict()
                    this.loadPurchaserHqCodeDict()
                    this.flag = false
                }
                if (arg === 1) {
                    this.ipagination.current = 1
                }
                let params = {'pageNo': this.ipagination.current, 'pageSize': this.ipagination.pageSize}
                params = this.getQueryParams()
                this.loading = true
                getAction(this.url.list, params).then((res) => {
                    if (res.success) {
                        this.dataSource = res.result.records
                        this.dataSource.forEach(item => {
                            if (this.dataSourceDailyDict.hasOwnProperty(item.dataSource)) {
                                item.dataSource = this.dataSourceDailyDict[item.dataSource]
                            }
                            if (this.subclassCodeDict.hasOwnProperty(item.subclassCode)) {
                                item.subclassCode = this.subclassCodeDict[item.subclassCode]
                            }
                            if (this.purchaserHqCodeDict.hasOwnProperty(item.purchaserCode)) {
                                item.purchaserCode = this.purchaserHqCodeDict[item.purchaserCode]
                            }
                        })
                        this.ipagination.total = res.result.total
                    }
                    if (res.code === 510) {
                        this.$message.warning(res.message)
                    }
                    this.loading = false
                })
            }
        }
    }
</script>
<style scoped>
    @import '~@assets/less/common.less'
</style>
